package 第4节面向对象;

import java.util.Comparator;
import java.util.Random;

public class TestArrayList {
    public static void main(String[] args) {
        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<String> list2 = new ArrayList<>();
        System.out.println(list1);
        System.out.println(list2);
//        System.out.println(list1.toString());
        list1.add(1);
        list1.add(2);
        list1.add(3);
        System.out.println(list1);
        list2.add("Hello");
        list2.add("World");
        System.out.println(list2);
        for (int num = 4; num <= 21; num++) {
            list1.add(num);
        }
        System.out.println(list1);

        for(int i = 0; i < 18; i++) {
            System.out.println(list1.delete(0));
            System.out.println(list1);
        }
        Random random = new Random();
        random.setSeed(666);
        for (int i = 0; i < 20; i++) {
            int index = random.nextInt(list1.size());
            list1.insert(index, random.nextInt(50));
        }
        System.out.println(list1);

        list1.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });
        System.out.println(list1);
        //
        System.out.println("=========================================");
        ArrayStack<Integer> stack = new ArrayStack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack);
        System.out.println(stack.peek());
        System.out.println(stack);
        System.out.println(stack.pop());
        System.out.println(stack);
    }
}
